<template>
	<view>
		<mylist :list="list1" :myType="myType" @subdel="subdel"></mylist>
		<view class="noMore" v-if="last_page==wantList.page&&list1.length!=0"
			style="text-align: center;color: #797575;margin-top: 20rpx;">
			数据加载完成...
		</view>
	</view>
</template>

<script>
	import {
		mylist
	} from "../components/mylist.vue"
	import {
		myWantBuyList,
		myOfferList
	} from '@/request/api.js'
	export default {
		props: {
			myType: {
				type: Number,
				default: 1
			}
		},
		components: {
			mylist
		},
		data() {
			return {
				list1: [],
				wantList: {
					page: 1
				},
				lastPage: 1,
				last_page: 1
			};
		},
		onReachBottom() {
			// this.$refs.community.reachBottom()
			// console.log('到达底部')
			// console.log(this.form.page,this.last_page)
			if (this.wantList.page < this.last_page) {
				this.wantList.page = this.wantList.page + 1
				if (this.myType == 1) {
					this.getList()
				} else {
					this.getQuotelist()
				}
			}
		},
		methods: {
			subdel(val){
				if(val){
					this.getList(val)
					console.log(val,'val')
				}
			},
			getList(e) {
				myWantBuyList(this.wantList).then(res => {
					if (res.code == 1) {
						// this.list1 = res.data.list
						this.list1 = (e=='subdel'? res.data.list: this.list1.concat(res.data.list))
						console.log(e=='subdel',this.list1,'list1')
						this.list1.map(item => {
							let arr = []
							item.specs_config.forEach(el => {
								if (el.value != '') {
									arr.push(el)
								}
							})
							item['newSpe'] = arr
						})
						
						this.last_page = Math.ceil(res.data.total / 10)
						// console.log(this.list1)
					}
				})
			},
			getQuotelist() {
				myOfferList(this.wantList).then(res => {
					if (res.code == 1) {
						this.list1 = this.list1.concat(res.data.list)
						this.list1.map(item => {
							let arr = []
							item.specs_config.forEach(el => {
								if (el.value != '') {
									arr.push(el)
								}
							})
							item['newSpe'] = arr
						})
						this.last_page = Math.ceil(res.data.total / 10)
						// console.log(this.list1)
					}
				})
			}
		},
		onLoad(res) {
			// console.log('111')
			this.myType = res.myType
			
			let title = this.myType == 1 ? '我的求购' : '我的报价'
			// console.log(this.myType,'myType')
			uni.setNavigationBarTitle({
				title: title
			});
		},
		onShow(){
			this.list1 = []
			if (this.myType == 1) {
				this.getList()
			} else {
				this.getQuotelist()
			}
			// console.log(this.subdel,'this.subdel')
		},
	}
</script>

<style lang="scss">

</style>
